<?php

namespace App\Http\Middleware;

use Closure;
// use Illuminate\Http\Request;
use App\Models\HomeModel;
use App\Http\Requests\MenuRequest;

class HomeMiddleware
{
    public $uid = 0;

    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function __construct()
    {
        $global = HomeModel::getGlobalVal();
        $nav = HomeModel::getNav();
        // dd($nav);
        view()->share(['global'=> $global,'nav'=>$nav]);
    }
    public function handle($request, Closure $next)
    {
        $url = $request->url();
        $arr = explode('/',$url);
        $action = end($arr);

        // if($action != 'login' && $action != 'code' && $action != 'userLogin'){
        //     if(empty(session('admin'))){
        //         // return redirect('backstage/login');
        //         echo '<script>top.location.href="http://'.$_SERVER['HTTP_HOST'].'/backstage/login";</script>';
        //     } 
        // }
        return $next($request);
    }



}
